package com.jar.exercise.设计模式.代理.动态代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author ZhangShengHao
 * @className ProxyFactory
 * @description TODO
 * @date 2020/1/26 22:14
 */
public class ProxyFactory {
	public static Object getInstance(Object o) {
		MyInvocation myInvocation = new MyInvocation(o);
		return Proxy.newProxyInstance(o.getClass().getClassLoader(), o.getClass().getInterfaces(), myInvocation);
	}
}

class MyInvocation implements InvocationHandler {
	/**
	 * 代理类
	 */
	private Object object;

	public MyInvocation(Object o) {
		this.object = o;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		return method.invoke(object, args);
	}
}

